package com.code.soulqlexpress.func;

import com.ql.util.express.ArraySwap;
import com.ql.util.express.InstructionSetContext;
import com.ql.util.express.OperateData;
import com.ql.util.express.instruction.op.OperatorBase;

/**
 * 表达式函数black_white
 * <p>
 * 从第一个参数开始算起，第一个不小于0的数
 *
 * @Author:jdy
 * @Date:2020/3/16
 * @Content:
 */
public class FirstGeZeroOperator extends OperatorBase {

    private static final long serialVersionUID = -419116845679389408L;

    @Override
    public OperateData executeInner(InstructionSetContext instructionSetContext, ArraySwap arraySwap) throws Exception {
        //第一个参数
        OperateData operateData = null;
        int length = arraySwap.length;
        for (int i = 0; i < length; i++) {
            operateData = arraySwap.get(i);
            final Object objectInner = operateData.getObjectInner(instructionSetContext);
            if (objectInner == null || Integer.parseInt(objectInner.toString()) < 0) {
                continue;
            }
            return operateData;
        }
        return new OperateData(-1, Integer.class);
    }
}
